<?php

/**
 * Louder Cache
 *
 * LICENSE
 *
 * This source file is subject to the New BSD License that is bundled
 * with this package in the file docs/LICENSE.txt.
 *
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to info@loudertechnology.com so we can send you a copy immediately.
 *
 * @category Louder
 * @package ClusterRequest
 * @copyright Copyright (c) 2005-2009 Andres Felipe Gutierrez (gutierrezandresfelipe at gmail.com)
 * @license New BSD License
 */

/**
 * Servidor que administrar las peticiones al cluster
 *
 * @category Louder
 * @package ClusterRequest
 * @copyright Copyright (c) 2005-2009 Andres Felipe Gutierrez (gutierrezandresfelipe at gmail.com)
 * @license New BSD License
 */
class ClusterRequest {

	/**
	 * Instancia unica de la clase
	 *
	 * @var ControllerRequest
	 */
	private static $_instance;

	/**
	 * Session ID de la petición
	 *
	 * @var string
	 */
	private $_sessionId;

	/**
	 * Constructor privado
	 *
	 */
	private function __construct(){

	}

	/**
	 * Devuelve la instancia del Singleton
	 *
	 * @return ClusterRequest
	 */
	public static function getInstance(){
		if(self::$_instance==null){
			self::$_instance = new ClusterRequest();
		}
		return self::$_instance;
	}

	/**
	 * Obtiene el ID de Session de la Peticion
	 *
	 * @return string
	 */
	public function getSessionId(){
		if(!$this->_sessionId){
			if(isset($_COOKIE['clusterSessID'])){
				$this->_sessionId = $_COOKIE['clusterSessID'];
			} else {
				$this->_sessionId = md5(uniqid(mt_rand()));
				setcookie("clusterSessID", $this->_sessionId);
			}
		}
		return $this->_sessionId;
	}

}
